"""
存放关于手机操作方法
屏幕尺寸 2400 X 1080
"""
import os
import time

from libs import Location


class Action:

    def __init__(self,debug=False):
        self.action_steps = []

    def tap(self, x: int, y: int):
        self.action_steps.append(f"adb shell input tap {x} {y}")
        return self

    def action_sleep(self, n):
        self.action_steps.append(f"sleep {n}")
        return self

    def perform(self):
        for cmd in self.action_steps:
            if cmd.startswith("sleep"):
                time.sleep(int(cmd.split(" ")[-1]))
            else:
                os.system(cmd)
        self.action_steps = []
        return self

    def swipe_screen(self, x=581, y=986, end_x=581, end_y=600):
        self.action_steps.append(f"adb shell input swipe {x} {y} {end_x} {end_y}")
        return self

    def input_god_number(self, number: int = -1):
        """物品数量输入器,-1表示直接输入最大值"""
        number_map = {"1": Location.PM_num_1, "2": Location.PM_num_2, "3": Location.PM_num_3,
                      "4": Location.PM_num_4, "5": Location.PM_num_5, "6": Location.PM_num_6,
                      "7": Location.PM_num_7, "8": Location.PM_num_8, "9": Location.PM_num_9,
                      "0": Location.PM_num_0}
        print(f"物品输入{number}")
        if number == -1:
            self.tap(*Location.PM_num_max)
        else:
            for s in str(number):
                # 按按钮
                self.tap(*number_map[s])
        return self


if __name__ == '__main__':
    Action().input_god_number(-1).perform()
